<?php
declare (strict_types = 1);

namespace app\common\service;

use think\facade\Request;
use app\common\model\AdminZdvoter as M;
use app\common\model\AdminZavote as MA;
use app\common\model\AdminZbuserinfo as MB;
use app\common\model\AdminZccandidate as MC;
use app\common\validate\AdminZdvoter as V;
use Symfony\Component\VarDumper\Cloner\Data;
use think\facade\Db;
use think\facade\Cache;

class AdminZdvoter
{
    // 删除
    public static function goRemove($id)
    {
        $model = M::find($id);
        if ($model->isEmpty()) return ['msg'=>'数据不存在','code'=>201];
        try{
            $model->delete();
        }catch (\Exception $e){
            return ['msg'=>'操作失败'.$e->getMessage(),'code'=>201];
        }
    }

    // 首页图表数据
    public static function goTubiaoshuju($biaoid)
    {
        $time = date("Y-m-d");
        $yi = M::where('biaoid', $biaoid)->where('riqi', $time)->count();

        $zuotian = date("Y-m-d",strtotime("-1 day"));
        $er = M::where('biaoid', $biaoid)->where('riqi', $zuotian)->count();

        $yizhouqian = date("Y-m-d",strtotime("-6 day"));
        $san = M::where('biaoid', $biaoid)->where('riqi', 'between', [$yizhouqian, $time])->count();
        
        $si = M::where('biaoid', $biaoid)->count();

        return ['msg'=>'操作成功','code'=>200,'data'=>['yi' =>$yi, 'er' => $er, 'san' => $san, 'si' => $si]];
    }  
    
}
